package com.example.controller;

/**
 * 功能：
 * 作者：snake
 * 日期：2024/2/4 下午 10:26
 */
import com.example.common.Result;
import com.example.entity.Address;
import com.example.service.AddressService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 联系人信息前端操作接口
 **/
@RestController
@RequestMapping("/address")
public class AddressController {

  @Resource
  private AddressService addressService;

  /**
   * 新增
   */
  @PostMapping("/add")
  public Result add(@RequestBody Address address) {
    addressService.add(address);
    return Result.success(address);
  }

  /**
   * 删除
   */
  @DeleteMapping("/delete/{id}")
  public Result deleteById(@PathVariable Integer id) {
    addressService.deleteById(id);
    return Result.success();
  }

  /**
   * 批量删除
   */
  @DeleteMapping("/delete/batch")
  public Result deleteBatch(@RequestBody List<Integer> ids) {
    addressService.deleteBatch(ids);
    return Result.success();
  }

  /**
   * 修改
   */
  @PutMapping("/update")
  public Result updateById(@RequestBody Address address) {
    addressService.updateById(address);
    return Result.success();
  }

  /**
   * 根据ID查询
   */
  @GetMapping("/selectById/{id}")
  public Result selectById(@PathVariable Integer id) {
    Address address = addressService.selectById(id);
    return Result.success(address);
  }

  /**
   * 查询所有
   */
  @GetMapping("/selectAll")
  public Result selectAll(Address address) {
    List<Address> list = addressService.selectAll(address);
    return Result.success(list);
  }

  /**
   * 分页查询
   */
  @GetMapping("/selectPage")
  public Result selectPage(Address address,
                           @RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize) {
    PageInfo<Address> page = addressService.selectPage(address, pageNum, pageSize);
    return Result.success(page);
  }

}
